package com.gamota.mobi.adapter;

import android.app.Activity;
import android.view.Gravity;

import com.devspark.appmsg.AppMsg;
import com.gamota.mobi.R;

public class ErrorHandler {

	private static ErrorHandler defaultInstance;
	private static transient Activity context;
	private static final int ALERT_DURATION = 4 * 1000;
	
	public static ErrorHandler getInstance() {
        if (defaultInstance == null) {
            synchronized (ErrorHandler.class) {
                if (defaultInstance == null) {
                    defaultInstance = new ErrorHandler();
                }
            }
        }
        return defaultInstance;
    }
	
	public ErrorHandler setContext(Activity context){
		ErrorHandler.context = context;
		return defaultInstance;
	}
	
	public void handleError(int errorCode){
		AppMsg msg;
		switch (errorCode) {
		case -1:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_nega1), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case -2:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_nega2), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case -3:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_nega3), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case -4:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_nega4), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 1:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_1), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 3:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_3), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 4:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_4), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 5:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_5), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 6:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_6), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 7:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_7), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 8:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_8), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 9:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_9), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 10:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code10), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 11:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_11), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 12:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_12), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 13:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_13), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 14:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_14), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 15:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_15), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 16:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_16), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 17:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_17), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 18:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_18), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 19:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_19), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 20:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_20), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 21:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_21), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 22:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_22), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 23:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_23), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 24:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_24), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 25:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_25), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 26:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_26), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 27:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_27), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 28:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_28), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 29:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_29), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 30:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_30), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 31:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_31), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 32:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_32), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 33:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_33), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 34:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_34), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 35:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_35), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 36:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_36), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 37:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_37), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 38:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_38), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 39:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_39), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 40:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_40), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 41:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_41), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 42:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_42), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 43:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_43), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 44:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_44), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 45:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_45), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 46:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_46), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 47:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_47), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 48:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_48), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 90:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_90), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 91:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code91), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case 401:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_401), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		case -101:
			msg = AppMsg.makeText(context, String.format(context.getResources().getString(R.string.error_code_nega101), errorCode), AppMsg.STYLE_ALERT, null);
			msg.setLayoutGravity(Gravity.TOP);
			msg.setDuration(ALERT_DURATION);
			msg.show();
			break;
		}
	}
}
